﻿import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	private static ArrayList<Student> studentList = new ArrayList<>();
	private static ArrayList<Course> courseList = new ArrayList<>();
	private static ArrayList<Class1> classList = new ArrayList<>();
	private static ArrayList<Score> scoreList = new ArrayList<>();
	static boolean isMenuShow=false;
	public static void main(String[] args){
		showMenu();
	}

	private static void showMenu() {
		while(true){
		// 为了避免程序疯狂运行造成死机 
		// 每秒钟检查一次是否要展示菜单
			try{
				Thread.sleep(1000);
			}catch(InterruptedException e){
				e.printStackTrace();
			}
			if(!isMenuShow){
				PrintUtil.printMenu(null);
				isMenuShow=true;
				
				Scanner sc=new Scanner(System.in);
				int i;
				try{
					i=sc.nextInt();
					switch(i){
					case 1:
					   studentList = StudentDao.queryStudentList();
					  PrintUtil.print(studentList);
					   break;
					case 2:
						courseList = CourseDao.queryCourseList();
						PrintUtil.print1(courseList);
						break;
					case 3:
						classList = ClassDao.queryclassList();
						PrintUtil.print2(classList);
						break;
					case 4:
						scoreList = ScoreDao.queryScoreList();
						PrintUtil.print3(scoreList);
						break;
					case 5:
						// 获取学生信息
						Student student=getStudentInfo();
						// 添加学生
//						StudentDao.addUseStatement(student);
						StudentDao.addUsePrepareStatement(student);
						break;
				    case 6:
				    	// 获取用户输入的学生姓名
						String name = getStudentName();
						// 按照姓名删除学生 
						StudentDao.del(name);
						break;
				    case 7:
				    	// 获取课程信息
						Course course=getCourseInfo();
						// 添加课程
						CourseDao.addUsePrepareStatement(course);
						break;
				    case 8:
				    	// 获取用户输入的课程名
						String kcm = getKcm();
						// 按照课程名删除课程
						CourseDao.del(kcm);
						break;
				    case 9:
				    	// 获取班级信息
				    	Class1 class2 = getClassInfo();
						// 添加班级
				    	ClassDao.addUsePrepareStatement(class2);
						break;
				    case 10:
				    	// 获取用户输入的班级名称
				    	String bjmc = getBjmc();
						// 按照班级名称删除班级
				    	ClassDao.del(bjmc);
						break;
				    case 11:
				    	// 获取学生成绩所属信息
				    	Score score = getScoreInfo();
						// 添加成绩
				    	ScoreDao.addUsePrepareStatement(score);
						break;
				    case 12:
				    	// 获取用户输入的学生姓名
				    	name = getStudentName();
						 kcm = getKcm();
						// 按照姓名删除学生 
						 ScoreDao.del(name,kcm);	
						 break;
					case 13:
						// 获取要修改的学生信息
						String name1 = getStudentName();
						// 获取要修改的字段
						int column = getUpdateColumn();
						// 获取要修改的值
						String value = getNewValue();
						// 更新学生表
						StudentDao.update(name1, column, value);
						break;
					case 14:
						// 获取要修改的课程信息
						String kcm1 = getKcm();
						// 获取要修改的字段
						int column1 = getUpdateColumn1();
						// 获取要修改的值
						String value1 = getNewValue1();
						// 更新课程表
						CourseDao.update1(kcm1, column1, value1);
						break;
					case 15:
						// 获取要修改的班级信息
						String bjmc1 = getBjmc();
						// 获取要修改的字段
						int column2 = getUpdateColumn2();
						// 获取要修改的值
						String value2 = getNewValue2();
						// 更新班级表
						ClassDao.update2(bjmc1, column2, value2);
						break;
					case 16:
						// 获取要修改的学生信息
						String name2 = getStudentName();
						// 通过学生姓名获取到学生的ID
						int id = StudentDao.getIdWithName(name2);
						// 通过CourseDao获取课程列表
						ArrayList<Course> courseList =  CourseDao.queryCourseList();
						// 打印课程列表
						PrintUtil.print1(courseList);
						// 获取用户选择的课程ID
						int kch = getSeletedKch();
						// 获取学生的选课成绩
						int cj = getCourseCJ();
						// 插入选课和成绩
						ScoreDao.add(id, kch, cj);
						break;
					case 17:
						// 退出程序
						System.exit(0);
						break;
						default:
					System.out.println("你的输入有误，请重新输入");
					break;
					}
				}catch(Exception e){
					System.out.println("你的输入有误，请重新输入");
				}
				isMenuShow=false;
		  }
		}
	}
	private static int getCourseCJ() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入课程成绩");
		int value = in.nextInt();
		return value;
	}

	private static int getSeletedKch() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入课程号");
		int value = in.nextInt();
		return value;
	}

	private static String getNewValue2() {
		Scanner in =new Scanner(System.in);
		System.out.println("请输入新的值");
		String value2 =in.nextLine();
		return value2;
	}

	private static int getUpdateColumn2() {
		Scanner in =new Scanner(System.in);
		System.out.println("请选择要更新的字段");
		System.out.println("1、班级名称");
		System.out.println("2、班级编号");
		System.out.println("3、年级");
		System.out.println("4、专业");
		
		
		int result2=in.nextInt();
		return result2;
	}

	private static String getNewValue1() {
		Scanner in =new Scanner(System.in);
		System.out.println("请输入新的值");
		String value1 =in.nextLine();
		return value1;
	}

	private static int getUpdateColumn1() {
		Scanner in =new Scanner(System.in);
		System.out.println("请选择要更新的字段");
		System.out.println("1、课程名");
		System.out.println("2、课程号");
		System.out.println("3、老师");
		
		int result1=in.nextInt();
		return result1;
	}


	private static String getNewValue() {
		Scanner in =new Scanner(System.in);
		System.out.println("请输入新的值");
		String value =in.nextLine();
		return value;
	}

	private static int getUpdateColumn() {
		Scanner in =new Scanner(System.in);
		System.out.println("请选择要更新的字段");
		System.out.println("1、姓名");
		System.out.println("2、年龄");
		System.out.println("3、性别");
		
		int result=in.nextInt();
		return result;
	}

	
	private static Score getScoreInfo() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入学生姓名");
		String name = in.nextLine();
		
		in = new Scanner(System.in);
		System.out.println("请输入学号");
		int id = in.nextInt();
				
		in = new Scanner(System.in);
		System.out.println("请输入课程名");
		String kcm = in.nextLine();
		
		in = new Scanner(System.in);
		System.out.println("请输入课程号");
		int kch = in.nextInt();
		
		in = new Scanner(System.in);
		System.out.println("请输入班级编号");
		int bjbh = in.nextInt();
		
		in = new Scanner(System.in);
		System.out.println("请输入成绩");
		int cj = in.nextInt();
		
		System.out.println("成绩信息输入完成");
		
		
		// 智能提示自动完成   ALT+？
		Score score =  new Score( name, kcm, cj);
		return score;
	}
	
	private static String getBjmc() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入班级名称");
		String bjmc = in.nextLine();
		return bjmc;
	}


	private static Class1 getClassInfo() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入班级编号");
		int bjbh = in.nextInt();
		
		in = new Scanner(System.in);
		System.out.println("请输入班级名称");
		String bjmc = in.nextLine();
		
		in = new Scanner(System.in);
		System.out.println("请输入班级所属年级");
		int nj = in.nextInt();
		
		in = new Scanner(System.in);
		System.out.println("请输入专业名");
		String zy = in.nextLine();
		
		System.out.println("班级信息输入完成");
		
		// 智能提示自动完成   ALT+？
		Class1 class2 =  new Class1(bjbh, bjmc ,nj, zy);
		return class2;
	}

	private static String getKcm() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入课程名");
		String kcm = in.nextLine();
		return kcm;
	}

	private static Course getCourseInfo() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入课程号");
		int kch = in.nextInt();
		
		in = new Scanner(System.in);
		System.out.println("请输入课程名");
		String kcm = in.nextLine();
		
		
		System.out.println("课程信息输入完成");
		
		// 智能提示自动完成   ALT+？
		Course course =  new Course(kch, kcm);
		return course;
	}

	private static String getStudentName() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入姓名");
		String name = in.nextLine();
		return name;
	}

	private static Student getStudentInfo() {
		Scanner in=new Scanner(System.in);
		System.out.println("请输入学号");
		int id=in.nextInt();
		
		in =new Scanner(System.in);
		System.out.println("请输入姓名");
		String name=in.nextLine();
		
		in =new Scanner(System.in);
		System.out.println("请输入年龄");
		int age=in.nextInt();
		
		in =new Scanner(System.in);
		System.out.println("请输入班级名称");
		String bjmc=in.nextLine();
		
		in =new Scanner(System.in);
		System.out.println("请输入专业");
		String zy=in.nextLine();
		
		in = new Scanner(System.in);
		System.out.println("请输入性别");
		String sex = in.nextLine();
			
		System.out.println("学生信息输入完成");
		
		// 智能提示自动完成   ALT+？
		Student student =  new Student(id, name, age, bjmc, zy, sex);
		return student;

	}
	
		
}

